/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bice.backbean;

import com.bice.controller.entity.BiceUser;
import com.bice.controller.entity.Post;
import com.bice.controller.service.PostService;
import com.bice.util.annotation.SessionUserResource;
import com.bice.util.annotation.SpringServiceResource;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Sirius
 */
@ManagedBean
@RequestScoped
public class CommunityBean extends BackBean {
    
    private String message;
    private BiceUser userTo;
    
    @SpringServiceResource
    private transient PostService postService;
    @SessionUserResource
    private BiceUser user;
    
    public CommunityBean() {
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
    
    public void post() {
        postService.post(user, getUserTo(), message);
        message = null;
    }

    public BiceUser getUserTo() {
        if(userTo == null) {
            userTo = user;
        }
        return userTo;
    }
    
    public List<Post> getPostsToLoggedUser() {
        return postService.getMessagesTo(user);
    }
    
}
